<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: SSD1306_OLED/128x64/SimpleTerminalOut/SimpleTerminalOut.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_s_s_d1306__o_l_e_d_2128x64_2_simple_terminal_out_2_simple_terminal_out_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">SSD1306_OLED/128x64/SimpleTerminalOut/SimpleTerminalOut.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>Simple terminal - output only</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - &lt;http://www.fabgl.com&gt;</span></div><div class="line"><span class="comment">  Copyright (c) 2019-2021 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* Please contact fdivitto2013@gmail.com if you need a commercial license.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* This library and related software is available under GPL v3.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment">  * OLED - SDA =&gt; GPIO 4</span></div><div class="line"><span class="comment">  * OLED - SCL =&gt; GPIO 15</span></div><div class="line"><span class="comment">  */</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#define OLED_SDA       GPIO_NUM_4</span></div><div class="line"><span class="preprocessor">#define OLED_SCL       GPIO_NUM_15</span></div><div class="line"><span class="preprocessor">#define OLED_ADDR      0x3C</span></div><div class="line"></div><div class="line"><span class="comment">// if your display hasn&#39;t RESET set to GPIO_UNUSED</span></div><div class="line"><span class="preprocessor">#define OLED_RESET     GPIO_UNUSED  // ie Heltec has GPIO_NUM_16 for reset</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><a name="_a0"></a><a class="code" href="classfabgl_1_1_i2_c.html">fabgl::I2C</a>               I2C;</div><div class="line"><a name="_a1"></a><a class="code" href="classfabgl_1_1_s_s_d1306_controller.html">fabgl::SSD1306Controller</a> DisplayController;</div><div class="line"><a name="_a2"></a><a class="code" href="classfabgl_1_1_terminal.html">fabgl::Terminal</a>          Terminal;</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> slowPrintf(<span class="keyword">const</span> <span class="keywordtype">char</span> * format, ...)</div><div class="line">{</div><div class="line">  va_list ap;</div><div class="line">  va_start(ap, format);</div><div class="line">  <span class="keywordtype">int</span> size = vsnprintf(<span class="keyword">nullptr</span>, 0, format, ap) + 1;</div><div class="line">  <span class="keywordflow">if</span> (size &gt; 0) {</div><div class="line">    va_end(ap);</div><div class="line">    va_start(ap, format);</div><div class="line">    <span class="keywordtype">char</span> buf[size + 1];</div><div class="line">    vsnprintf(buf, size, format, ap);</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; size; ++i) {</div><div class="line">      Terminal.<a name="a3"></a><a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(buf[i]);</div><div class="line">      delay(45);</div><div class="line">    }</div><div class="line">  }</div><div class="line">  va_end(ap);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> demo1()</div><div class="line">{</div><div class="line">  Terminal.<a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(<span class="stringliteral">&quot;\e[40;32m&quot;</span>); <span class="comment">// background: black, foreground: green</span></div><div class="line">  Terminal.<a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(<span class="stringliteral">&quot;\e[2J&quot;</span>);     <span class="comment">// clear screen</span></div><div class="line">  Terminal.<a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(<span class="stringliteral">&quot;\e[1;1H&quot;</span>);   <span class="comment">// move cursor to 1,1</span></div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[1mWELCOME TO FabGL\e[0m\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;www.fabgl.com\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;================\r\n\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;This is a Display Controller, PS2 Mouse and Keyboard Controller, Graphics Library, Game Engine and ANSI/VT Terminal for the ESP32\r\n\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;Current settings\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;Screen Size:\r\n  \e[1m%d x %d\e[0m\r\n&quot;</span>, DisplayController.<a name="a4"></a><a class="code" href="classfabgl_1_1_base_display_controller_a749df909b39fd096bf6e2813f2f5324c.html#a749df909b39fd096bf6e2813f2f5324c">getScreenWidth</a>(), DisplayController.<a name="a5"></a><a class="code" href="classfabgl_1_1_base_display_controller_a0872427e4a351bb3590e8d00096e9cba.html#a0872427e4a351bb3590e8d00096e9cba">getScreenHeight</a>());</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;Terminal Size:\r\n  \e[1m%d x %d\e[0m\r\n&quot;</span>, Terminal.<a name="a6"></a><a class="code" href="classfabgl_1_1_terminal_a6e9094a53fd8a44ad7a061abae461e5c.html#a6e9094a53fd8a44ad7a061abae461e5c">getColumns</a>(), Terminal.<a name="a7"></a><a class="code" href="classfabgl_1_1_terminal_a1bb8ac2a73a5d9e6256505e1bf51c6a9.html#a1bb8ac2a73a5d9e6256505e1bf51c6a9">getRows</a>());</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;Free Memory:\r\n  \e[1m%d bytes\e[0m\r\n\n&quot;</span>, heap_caps_get_free_size(MALLOC_CAP_8BIT));</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> demo3()</div><div class="line">{</div><div class="line">  Terminal.<a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(<span class="stringliteral">&quot;\e[40;32m&quot;</span>); <span class="comment">// background: black, foreground: green</span></div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\nSupported styles:\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[0mNormal\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[1mBold\e[0m\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[3mItalic\e[0m\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[4mUnderlined\e[0m\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[5mBlink\e[0m\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[7mInverse\e[0m\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[1;3mBoldItalic\e[0m\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e#6Double W.\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e#6\e#3Double H.\r\n&quot;</span>); <span class="comment">// top half</span></div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e#6\e#4Double H.\r\n&quot;</span>); <span class="comment">// bottom half</span></div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> demo4()</div><div class="line">{</div><div class="line">  Canvas cv(&amp;DisplayController);</div><div class="line">  Terminal.<a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(<span class="stringliteral">&quot;\e[40;32m&quot;</span>); <span class="comment">// background: black, foreground: green</span></div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\nMixed text and graphics:\r\n&quot;</span>);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;Points...\r\n&quot;</span>);</div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 100; ++i) {</div><div class="line">    cv.setPenColor(random(256), random(256), random(256));</div><div class="line">    cv.setPixel(random(cv.getWidth()), random(cv.getHeight()));</div><div class="line">    delay(15);</div><div class="line">  }</div><div class="line">  delay(500);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[40;32mLines...\r\n&quot;</span>);</div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 10; ++i) {</div><div class="line">    cv.setPenColor(random(256), random(256), random(256));</div><div class="line">    cv.drawLine(random(cv.getWidth()), random(cv.getHeight()), random(cv.getWidth()), random(cv.getHeight()));</div><div class="line">    delay(50);</div><div class="line">  }</div><div class="line">  delay(500);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[40;32mRectangles...\r\n&quot;</span>);</div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 10; ++i) {</div><div class="line">    cv.setPenColor(random(256), random(256), random(256));</div><div class="line">    cv.drawRectangle(random(cv.getWidth()), random(cv.getHeight()), random(cv.getWidth()), random(cv.getHeight()));</div><div class="line">    delay(50);</div><div class="line">  }</div><div class="line">  delay(500);</div><div class="line">  slowPrintf(<span class="stringliteral">&quot;\e[40;32mEllipses...\r\n&quot;</span>);</div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 10; ++i) {</div><div class="line">    cv.setPenColor(random(256), random(256), random(256));</div><div class="line">    cv.drawEllipse(random(cv.getWidth()), random(cv.getHeight()), random(cv.getWidth()), random(cv.getHeight()));</div><div class="line">    delay(50);</div><div class="line">  }</div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 30; ++i) {</div><div class="line">    Terminal.<a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(<span class="stringliteral">&quot;\e[40;32mScrolling...\r\n&quot;</span>);</div><div class="line">    delay(250);</div><div class="line">  }</div><div class="line">  cv.clear();</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  Serial.begin(115200); delay(500); Serial.write(<span class="stringliteral">&quot;\n\n\n&quot;</span>); <span class="comment">// DEBUG ONLY</span></div><div class="line"></div><div class="line">  I2C.<a name="a8"></a><a class="code" href="classfabgl_1_1_i2_c_abdd72a91fee181ca1b9eb05120e60a28.html#abdd72a91fee181ca1b9eb05120e60a28">begin</a>(OLED_SDA, OLED_SCL);</div><div class="line"></div><div class="line">  DisplayController.<a name="a9"></a><a class="code" href="classfabgl_1_1_s_s_d1306_controller_af4457c33ec3247fb92c8bf2a2d8e9819.html#af4457c33ec3247fb92c8bf2a2d8e9819">begin</a>(&amp;I2C, OLED_ADDR, OLED_RESET);</div><div class="line">  DisplayController.<a name="a10"></a><a class="code" href="classfabgl_1_1_s_s_d1306_controller_a2ac60f74ade23bfba42ef0985635589d.html#a2ac60f74ade23bfba42ef0985635589d">setResolution</a>(<a name="a11"></a><a class="code" href="fabglconf_8h_a48a7b2c95a1f0546c72310844fa6fc74.html#a48a7b2c95a1f0546c72310844fa6fc74">OLED_128x64</a>);</div><div class="line"></div><div class="line">  <span class="keywordflow">while</span> (DisplayController.<a name="a12"></a><a class="code" href="classfabgl_1_1_s_s_d1306_controller_a4a47f12debf6d5d7273c3e5fb360417a.html#a4a47f12debf6d5d7273c3e5fb360417a">available</a>() == <span class="keyword">false</span>) {</div><div class="line">    Serial.write(<span class="stringliteral">&quot;Error, SSD1306 not available!\n&quot;</span>);</div><div class="line">    delay(5000);</div><div class="line">  }</div><div class="line"></div><div class="line">  Terminal.<a name="a13"></a><a class="code" href="classfabgl_1_1_terminal_aebaecc1fa474fddc48dd5778024b19a5.html#aebaecc1fa474fddc48dd5778024b19a5">begin</a>(&amp;DisplayController);</div><div class="line">  Terminal.<a name="a14"></a><a class="code" href="classfabgl_1_1_terminal_a4b5a116dd0c23f47197ff61b5d9d7f41.html#a4b5a116dd0c23f47197ff61b5d9d7f41">setLogStream</a>(Serial);  <span class="comment">// DEBUG ONLY</span></div><div class="line">  Terminal.<a name="a15"></a><a class="code" href="classfabgl_1_1_terminal_a72770033c3a06f499a251909efba87c7.html#a72770033c3a06f499a251909efba87c7">loadFont</a>(&amp;fabgl::FONT_6x8);</div><div class="line">  Terminal.<a name="a16"></a><a class="code" href="classfabgl_1_1_terminal_aace245bfe6cab7b4339bd691077e1c23.html#aace245bfe6cab7b4339bd691077e1c23">enableCursor</a>(<span class="keyword">true</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  delay(1000);</div><div class="line">  demo1();</div><div class="line">  delay(4000);</div><div class="line">  demo3();</div><div class="line">  delay(4000);</div><div class="line">  demo4();</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 2 2021 07:08:02 for FabGL by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
